<?php

/*      index.php      */
/*    sun&ride GmbH    */

//Includes
require_once("includes.php");
include('database.php');
if (isset($_GET['section'])) {
    //Section auslesen
    $section = $_GET['section'];
    //Page Title Suffix auswählen
    $smarty->assign('title_suffix', get_page_title($section));
    //Template File auswählen
    $tpl_file = $section . ".tpl";
    //Page Style auswählen
    $style = get_page_style($section);
    //Intro auf false setzen
    $smarty->assign('intro', false);
    //Produkte für den Header auslesen
    $smarty->assign('products', get_products());
    if($section == "about"){
        $staff=array();
        $staff_count = mysql_fetch_array(mysql_query("SELECT count(id) FROM staff"));
        for($i=1; $i<=$staff_count[0];$i=$i+1){
            $r_staff = mysql_fetch_array(mysql_query("SELECT * FROM staff WHERE ID = ".$i));
            $r_dep = mysql_fetch_array(mysql_query("SELECT * FROM departments WHERE ID = ".$r_staff[3]));
            $staff[$i]="<tr><td>$r_staff[1] $r_staff[2]</td><td>$r_dep[1]</td></tr>";
        }
        $smarty->assign('staff', $staff);
    }
} else {
    $tpl_file = "intro.tpl";
    $title = "";
    $style = "style_intro.css";
    $smarty->assign('intro', true);
    $smarty->assign('title_suffix', $title);
}
//Templatefile übergeben
$smarty->assign('tpl_file', $tpl_file);
//Stylefile übergeben
$smarty->assign('site_style', $style);
//Weiterleitung zur Products.php
if(isset($_GET['section'])){
    if (!($_GET['section'] == "products")) { //Wenn section != products
        $smarty->display('site.tpl');
    } else { //Wenn section == products
        if (isset($_GET['productid'])) {
            $productid = $_GET['productid'];
            header("Location: http://127.0.0.1/products.php?productid=$productid");
        } else {
            header("Location: http://127.0.0.1/products.php");
        }
    }
}else{
   $smarty->display('site.tpl'); 
}
?>
